package com.sunrin.applepie.gm_player.activity;

import com.sunrin.applepie.gm_player.model.MainTabItemModel;
import android.os.Bundle;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

public class MainTabActivity extends TabActivity implements OnTabChangeListener {
	private TabHost tabHost;
	private final int TabHeight = 120;

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		setContentView(R.layout.tab_main);

		tabHost = getTabHost();

		AddTabItem("title", getResources().getString(R.string.tab_title),
				Tab_TitleActivity.class);
		AddTabItem("art", getResources().getString(R.string.tab_art),
				Tab_ArtActivity.class);
		AddTabItem("album", getResources().getString(R.string.tab_album),
				Tab_AlbumActivity.class);
		AddTabItem("list", getResources().getString(R.string.tab_list),
				Tab_ListActivity.class);

		setTabProperty(this.TabHeight);
		tabHost.setCurrentTab(0);
		tabHost.setOnTabChangedListener(this);
		tabHost.getTabWidget().getChildAt(0)
				.setBackgroundColor(Color.parseColor("gray"));
	}

	public void AddTabItem(String tag, String name, Class<?> cls) {
		Intent intent = new Intent().setClass(this, cls).addFlags(
				Intent.FLAG_ACTIVITY_CLEAR_TOP);
		TabHost.TabSpec spec = tabHost.newTabSpec(tag)
				.setIndicator(new MainTabItemModel(this, name))
				.setContent(intent);
		tabHost.addTab(spec);
	}

	public void setTabProperty(int height) {
		for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
			tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = height;
			tabHost.getTabWidget().getChildAt(i)
					.setBackgroundColor(Color.parseColor("white"));
		}
	}

	public void onTabChanged(String arg0) {
		// TODO Auto-generated method stub
		for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
			tabHost.getTabWidget().getChildAt(i)
					.setBackgroundColor(Color.parseColor("white"));
		}
		tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab())
				.setBackgroundColor(Color.parseColor("gray"));
	}

}
